package com.nineclock.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nineclock.system.pojo.SysCompanyUser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;


public interface SysCompanyUserMapper extends BaseMapper<SysCompanyUser> {

    /**
     * 根据企业的ID更新企业员工的公司名称
     * @param companyName
     * @param companyId
     */
    @Update("update sys_company_user set company_name = #{companyName} where company_id = #{companyId}")
    public void updateCompanyUserByCompanyId(@Param("companyName") String companyName, @Param("companyId") Long companyId);

    /**
     * 查询企业系统管理员
     * @param companyId
     * @return
     */
    @Select("select \n" +
            "u.* \n" +
            "from \n" +
            "sys_company_user u, \n" +
            "sys_company_user_role ur , \n" +
            "sys_role r \n" +
            "where \n" +
            "u.id = ur.company_user_id and \n" +
            "ur.role_id = r.id and ur.company_id = #{companyId} and r.role_name = 'ROLE_ADMIN_SYS'")
    public SysCompanyUser queryCurrentAdminByCompanyId(@Param("companyId") Long companyId);

    /**
     * 查询工号对应的用户数量
     * @param workNum
     * @return
     */
    @Select("select count(*) from sys_company_user where work_number = #{workNum}")
    public Integer countByWorknum(@Param("workNum") String workNum);


}
